package 贪心;

public class 贪心2_摆动序列 {

    public int wiggleMaxLength(int[] nums) {
        if(nums.length<=1)return nums.length;
        int prevdiff=0;
        int curdiff=0;
        int cnt=1;
        if(nums.length==2){
            curdiff=nums[1]-nums[0];
            if(curdiff!=prevdiff)cnt++;
        }else {
            for(int i=1;i<nums.length;i++){
                curdiff=nums[i]-nums[i-1];
                if((prevdiff>=0&&curdiff<0)||(prevdiff<=0&&curdiff>0)){
                    cnt++;
                    prevdiff=curdiff;
                }
            }
        }
        return cnt;
    }
    public static void main(String[] args) {
        int[] nums={1,7,4,9,2,5};
        new 贪心2_摆动序列().wiggleMaxLength(nums);
    }
}
